
namespace heavenlyBody {
    export async function run() {
        loadBeginScene();
    }

    async function loadBeginScene() {
        await RES.loadConfig("default.res.json", "/resource");
        // await RES.getResAsync("star3_1_png");
        // await RES.getResAsync("star3_2_png");
        // await RES.getResAsync("star3_3_png");
        // await RES.getResAsync("Assets/star/starbg_day.jpg");
        // await RES.getResAsync("Assets/star/starbg_night.jpg");
        await SceneManager.instance.loadBegin();
        let _camObj = paper.GameObject.find("Main Camera");
        _camObj.activeSelf = false;
        let _cam = _camObj ? _camObj.getComponent(egret3d.Camera) : egret3d.Camera.main;
        _cam.order = 0;
    }
}

class ThemeAdapter implements eui.IThemeAdapter {

    public getTheme(url: string, onSuccess: Function, onError: Function, thisObject: any): void {

        function onResGet(e: string): void {
            onSuccess.call(thisObject, e);
        }
        function onResError(e: RES.ResourceEvent): void {
            if (e.resItem.url == url) {
                RES.removeEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, onResError, null);
                onError.call(thisObject);
            }
        }

        if (typeof generateEUI !== 'undefined') {
            egret.callLater(() => {
                onSuccess.call(thisObject, generateEUI);
            }, this);
        }
        else if (typeof generateEUI2 !== 'undefined') {
            RES.getResByUrl("resource/gameEui.json", (data, url) => {
                window["JSONParseClass"]["setData"](data);
                egret.callLater(() => {
                    onSuccess.call(thisObject, generateEUI2);
                }, this);
            }, this, RES.ResourceItem.TYPE_JSON);
        }
        else {
            RES.addEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, onResError, null);
            RES.getResByUrl(url, onResGet, this, RES.ResourceItem.TYPE_TEXT);
        }
    }
}


declare var generateEUI: { paths: string[], skins: any }
declare var generateEUI2: { paths: string[], skins: any }

class AssetAdapter implements eui.IAssetAdapter {

    public getAsset(source: string, compFunc: Function, thisObject: any): void {
        function onGetRes(data: any): void {
            compFunc.call(thisObject, data, source);
        }
        let data = RES.getRes(source);
        if (data) {
            onGetRes(data);
        }
        else {
            RES.getResAsync(source, onGetRes, this);
        }
    }
}

window["heavenlyBody"] = heavenlyBody;